package uk.ac.lkl.lpp.model;



//import java.util.Collection;
import java.util.Map;

import uk.ac.lkl.lpp.model.ldo.TeachingMethod;


public class TeachingMethodSpecifiedHoursFieldGroup extends
        TeachingMethodFieldGroup {

    private Map<TeachingMethod, Float> hoursMap;

    PedagogyPlanModel model;

    public TeachingMethodSpecifiedHoursFieldGroup(PedagogyPlanModel model) {
        super(model);
        this.model = model;
        hoursMap = model.getMap(
                                "TeachingMethodHoursAllocation",
                                TeachingMethod.class,
                                Float.class);
    }


    protected Object getField(int listIndex,
                              TeachingMethod teachingMethod,
                              int fieldIndex) {
        return hoursMap.get(teachingMethod);
    }


    // need to notify listeners that has changed
    protected void setField(TeachingMethod teachingMethod,
                            int fieldIndex,
                            Object object) {
        Float hours = (Float) object;
        hoursMap.put(teachingMethod, hours);
    }


    @Override
    public String getFieldName(int fieldIndex) {
        return  model.getTime_unit();//"Hours";
    }


    @Override
    protected Class getClass(int fieldIndex) {
        return Float.class;
    }


    @Override
    public int size() {
        return 1;
    }


    @Override
    public boolean isEditable(TeachingMethod teachingMethod, int fieldIndex) {
        return true;
    }


    @Override
    public boolean isPermanent() {
        return false;
    }


    @Override
    public String getName() {
        return model.getTime_unit();//"Hours";
    }


    @Override
    public Object calculateTotal(int fieldIndex) {
        Float total = 0.0f;
        for (Float hours : hoursMap.values())
            if (hours != null)
                total += hours;
        return total;
    }
}
